package proxy;

import java.io.InputStream;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;

public class ProxyService {

	public static void main(String[] args) {     
		    try {     
		        URL url = new URL("http://www.baidu.com");     
		        // 创建代理服务器     
		       InetSocketAddress addr = new InetSocketAddress("192.168.0.254",     
		                8080);     
		        // Proxy proxy = new Proxy(Proxy.Type.SOCKS, addr); // Socket 代理     
		       Proxy proxy = new Proxy(Proxy.Type.HTTP, addr); // http 代理     
		        // 如果我们知道代理server的名字, 可以直接使用     
		        // 结束     
		        URLConnection conn = url.openConnection(proxy);     
		        InputStream in = conn.getInputStream();     
		        // InputStream in = url.openStream();     
		        String s = null;//IOUtils.toString(in);     
		        System.out.println(s);     
		    } catch (Exception e) {     
		        e.printStackTrace();     
		    }     
		} 

}
